package com.baibang.baibang815.controller;

import com.baibang.baibang815.domain.Product;
import com.baibang.baibang815.service.ProductService;
import com.baibang.baibang815.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
@Api(tags = "商品管理")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/getProductListAll")
    @ApiOperation(value = "获取商品列表")
    public AjaxResult getProductListAll() {
        // 白帮 0815
        return AjaxResult.success(productService.selectAll());
    }

    @GetMapping("/getProductById")
    @ApiOperation(value = "根据ID查询商品信息")
    public AjaxResult getProductById(@RequestParam int id) {
        // 白帮 0815
        return AjaxResult.success(productService.selectById(id));
    }

    @PostMapping("/addProduct")
    @ApiOperation(value = "新增商品")
    public AjaxResult addProduct(@RequestBody Product product) {
        // 白帮 0815
        return AjaxResult.success(productService.saveProduct(product));
    }

    @PostMapping("/updateProduct")
    @ApiOperation(value = "修改商品信息")
    public AjaxResult updateProduct(@RequestBody Product product) {
        // 白帮 0815
        return AjaxResult.success(productService.updateProduct(product));
    }

    @PostMapping("/deleteProduct")
    @ApiOperation(value = "删除商品")
    public AjaxResult deleteProduct(@RequestParam int id) {
        // 白帮 0815
        return AjaxResult.success(productService.deleteProduct(id));
    }
}